/**
 * Wihidum - Efficient Broker Hierarchy for Publish Subscribe Middleware
 *
 * License      :   Apache License 2.0
 * Home Page    :   http://code.google.com/p/wihidum/
 * Mailing List :   wihidum@googlegroups.com
 */

package lk.mrt.cse.wihidum.subscriber.receiver;

import org.apache.axis2.receivers.AbstractMessageReceiver;
import org.apache.axis2.context.MessageContext;
import org.apache.log4j.Logger;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.om.OMException;
import lk.mrt.cse.wihidum.util.WihidumConstants;
import lk.mrt.cse.wihidum.util.WSEventingConstants;
import lk.mrt.cse.wihidum.client.BrokerRetrievalClient;

public class InOnlyMessageReceiver extends AbstractMessageReceiver
{
    private static final Logger logger = Logger.getLogger (MessageReceiver.class);

    public InOnlyMessageReceiver()
    {

    }

    public void invokeBusinessLogic(MessageContext inMessageContext)
    {
        logger.info("Subscriber Service Received a new message");
         try
         {
             SOAPEnvelope inSoapEnvelope=inMessageContext.getEnvelope();
             String action=inMessageContext.getOptions().getAction();

             if (action.equals (WihidumConstants.Operations.Update_Client))
             {
                logger.info("Recieved message is a update client on brokers message.");
                BrokerRetrievalClient brokerRetrievalClient=new BrokerRetrievalClient();
                brokerRetrievalClient.processGetBrokersMessage(inSoapEnvelope, WSEventingConstants.ElementNames.Update_Client);

             }

         }
         catch (NullPointerException ex)
        {
            logger.error ("Error in recognizing received message format", ex);
        }
        catch (OMException ex)
        {
            logger.error ("Error in recognizing received message format", ex);
        }

    }
}
